#ifndef __MARS_CORE_WEAK_PTR_H__
#define __MARS_CORE_WEAK_PTR_H__


namespace Core
{

template< typename T >
class WeakPtr
{
private:
	typedef T reference_type;

public:
	WeakPtr();
	WeakPtr( reference_type* ref );
	WeakPtr( const WeakPtr& ptr );

	~WeakPtr();

	WeakPtr&						operator = ( reference_type* ref );
	WeakPtr&						operator = ( const WeakPtr& ptr );

	reference_type*					operator -> () const;

	reference_type*					GetPointer();
	const reference_type*			GetPointer() const;

private:
	reference_type*					m_pReference;
};

template< typename T >
WeakPtr< T >::WeakPtr()
	: m_pReference( NULL )
{

}

template< typename T >
WeakPtr< T >::WeakPtr( reference_type* ref )
{
	m_pReference = ref;
}

template< typename T >
WeakPtr< T >::WeakPtr( const WeakPtr& ptr )
{
	m_pReference = ptr.m_pReference;
}

template< typename T >
WeakPtr< T >::~WeakPtr()
{
	m_pReference = NULL;
}

template< typename T >
WeakPtr< T >&	WeakPtr< T >::operator = ( reference_type* ref )
{
	m_pReference = ref;
	return *this;
}

template< typename T >
WeakPtr< T >&	WeakPtr< T >::operator = ( const WeakPtr& ptr )
{
	return *this = ptr->m_pReference;
}

template< typename T >
T*	WeakPtr< T >::operator -> () const
{
	return m_pReference;
}

template< typename T >
T*	WeakPtr< T >::GetPointer()
{
	return m_pReference;
}

template< typename T >
const T* WeakPtr< T >::GetPointer() const
{
	return m_pReference;
}

} // end of namespace Core


#endif // end of #ifndef __MARS_CORE_WEAK_PTR_H__